<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <!-- https://juejin.cn/post/7004638318843412493 -->
    <script>
   
        setTimeout(
            function () {//宏任务1
            console.log("1");//stdout-8
        }, 0);
        async function async1() {
            console.log("2");//stdout-1
            const data = await async2();
            console.log("3");//stdout-5
            return data;
        }
        async function async2() {
            return new Promise((resolve) => {
                console.log("4");//stdout-2
                resolve("async2的结果");
            }).then((data) => {//微任务1
                console.log("5");//stdout-4
                return data;
            });
        }
        async1().
        then((data) => {//微任务2
            console.log("6");//stdout-6
            console.log(data);//stdout-7
        });
        new Promise(function (resolve) {
            console.log("7");//stdout-3
            //   resolve()
        }).then(function () {
            console.log("8");
        });
        // 结果
        //  2
        //  4
        //  7
        //  5
        //  3
        //  6
        //  async2的结果
        //  1
    </script>
</body>

</html>